<template>
  <div>
    <!-- 定价子任务页面     --------------------------------------------------------- -->
    <!-- <el-dialog
      v-dialogDrag
      :title="titleName"
      :visible.sync="subRecord"
      width="1024px"
    > -->
    <span class="formTitle"><i class="vertical-bar"></i>{{ title }}</span>

      <el-form
        :model="recordForm"
        ref="subRecordRef"
        label-width="100px"
        label-position="right"
      >
        <el-row>
          <el-col :span="5" :offset="1">
            <el-form-item label="任务名称：" prop="taskName">
              <el-input
                v-model="recordForm.taskName"
                maxlength="32"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5" :offset="2">
            <el-form-item label="定价编号：" prop="pricingCode">
              <el-input
                v-model="recordForm.pricingCode"
                maxlength="32"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5" :offset="2">
            <el-form-item label="数据日期：" prop="dataDate">
              <el-input
                v-model="recordForm.dataDate"
                maxlength="32"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="container">
          <el-col style="margin-right:10px;" class="content-left">
            <upper-template :searchIcon="false" :configIcon="false">
              <!-- 操作按钮区 -->
              <template slot="buttonArea">
                <el-button @click="toBlock()">引擎任务</el-button>
                <el-button @click="toRecord()">执行记录</el-button>
              <el-button @click="goBack()">返回</el-button>
              </template>
            </upper-template>
          </el-col>
        </el-row>
        <el-table
          ref="subRecordModelTable"
          :data="subRecordModelData"
          style="width: 100%"
          @row-click="authorizeModelFor"
        >
          <el-table-column
            prop="pricingCode"
            label="定价编号"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="subTaskCode"
            label="子任务编号"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="dataDate"
            label="数据日期"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="startTm"
            label="开始时间"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="endTm"
            label="结束时间"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="status"
            label="运行状态"
            :show-overflow-tooltip="true"
            :formatter="formatRunStatus"
          ></el-table-column>
        </el-table>
       <!-- 分页插件 -->
        <pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="recordForm.page"
          :page-size="recordForm.size"
          @refresh="toSubRecord"
          :total="total"
        ></pagination>
      </el-form>
    <!-- </el-dialog> -->

    <!-- 定价引擎任务页面     --------------------------------------------------------- -->
    <el-dialog
      v-dialogDrag
      :title="blocktitleName"
      :visible.sync="block"
      width="1024px"
       :append-to-body="true"
    >
      <el-form
        :model="blockForm"
        ref="blockRef"
        label-width="100px"
        label-position="right"
      >
      
        <el-row>
          <el-col :span="6" :offset="1">
            <el-form-item label="任务名称：" prop="taskName">
              <el-input
                v-model="blockForm.taskName"
                maxlength="32"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item label="定价编号：" prop="pricingCode">
              <el-input
                v-model="blockForm.pricingCode"
                maxlength="32"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item label="数据日期：" prop="dataDate">
              <el-input
                v-model="blockForm.dataDate"
                maxlength="32"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" :offset="1">
            <el-form-item label="表名称：" prop="positions">
              <el-select
                v-model="blockForm.pdName"
                style="width:100%"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in positionOptions"
                  :key="item.pdPostfix"
                  :label="item.pdName"
                  :value="item.pdPostfix"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item label="运行状态：" prop="status">
              <el-select
                v-model="blockForm.status"
                style="width:100%"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in statusOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="container">
          <el-col style="margin-right:10px;" class="content-left">
            <upper-template :searchIcon="false" :configIcon="false">
              <!-- 操作按钮区 -->
              <template slot="buttonArea">
                <el-button @click="blockquery()">查询</el-button>
                <el-button @click="toRecord()">执行记录</el-button>
                <el-button @click="toSubRecord()">子任务</el-button>
                <el-button @click="goBack()">返回</el-button>
              </template>
            </upper-template>
          </el-col>
        </el-row>
        <el-table
          ref="blockModelTable"
          :data="blockModelData"
          style="width: 100%"
          @row-click="authorizeModelFor"
        >
          <el-table-column
            prop="tableName"
            label="表名称"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="blockSize"
            label="块大小"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="dataDate"
            label="数据日期"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="startAccount"
            label="开始编号"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="endAccount"
            label="结束编号"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="successNum"
            label="成功记录数"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="failNum"
            label="失败记录数"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="startTm"
            label="开始时间"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="endTm"
            label="结束时间"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="status"
            label="运行状态"
            :show-overflow-tooltip="true"
          ></el-table-column>
        </el-table>
        <!-- 分页插件 -->
        <pagination
          @size-change="blockhandleSizeChange"
          @current-change="blockhandleCurrentChange"
          :current-page="blockForm.page"
          :page-size="blockForm.size"
          @refresh="toBlock"
          :total="blocktotal"
        ></pagination>
      </el-form>
    </el-dialog>
        <!-- 定价执行记录页面 --------------------------- -->
    <el-dialog
      v-dialogDrag
      :title="recordtitleName"
      :visible.sync="recordDi"
      width="80%"
      top="2%"
      :append-to-body="true"
    >
      <positionRecordForm ref="recordForm" :code="code" />
      <div slot="footer">
        <!-- <el-button @click="saveFunc">确 定</el-button> -->
        <el-button @click="recordDi = false">返 回</el-button>
      </div>
    </el-dialog>
  </div>
  
</template>

<script>
import { getDict } from "@/api/getDict";
import { pricingTask } from "@/api/index";
import positionRecordForm from "./pricingTask_record";
export default {
  props: {
    //选中的值
    baseData: {
      type: Object,
      default: () => ({})
    },
    title: String
  },
  data() {
    return {
      //执行记录页面
      recordtitleName: "定价执行记录",
      recordDi: false,
      code: "",
      //引擎任务页面
      blocktotal:null,
      positionOptions: {},
      statusOption: {},
      blocktitleName: "引擎任务",
      blockModelData: [],
      blockForm: {},
      block: false,
      //定价子任务表单数据
      total:null,
      subRecordModelData: [],
      //定价子任务界面上方数据
      recordForm: { 
        taskName: this.baseData.taskName,
        pricingCode: this.baseData.pricingCode,
        dataDate: this.baseData.dataDate,
        page: 1,
        size: 15
         },
      titleName: "定价子任务",
      subRecord: true,
      searchForm: {},
      tableData: [],
      textData: [
        { prop: "pricingCode", label: "定价编号", disabled: true },
        { prop: "dataDate", label: "数据日期", disabled: true },
        { prop: "sceneCode", label: "情景编号", disabled: true },
        { prop: "sceneVersion", label: "情景版本", disabled: true },
        { prop: "startTm", label: "开始时间", disabled: true },
        { prop: "endTm", label: "结束时间", disabled: true },
        { prop: "successNum", label: "成功记录", disabled: true },
        { prop: "failNum", label: "失败记录", disabled: true },
        { prop: "status", label: "执行记录", disabled: true },
      ],
      checkList: [],
    };
  },
  watch: {
    baseData: function(newVal, oldVal) {
      if (newVal != oldVal) {
        this.recordForm = { ...newVal, page: 1, size: 15 };
      } else {
      }
    }
  },
  components: {
    positionRecordForm,
  },
  created() {
    this.searchFunc();
    this.toSubRecord();
  },
  computed: {},
  mounted() {},
  methods: {
    refreshGrid(){
      this.toSubRecord();
    },
    blockquery(){
      let data ={
        taskCode:this.blockForm.taskCode,
        pricingCode:this.blockForm.pricingCode,
        dataDate:this.recordForm.dataDate,
        tableName:this.blockForm.pdName,
        status:this.blockForm.status,
        page:this.blockForm.page,
        size:this.blockForm.size,
      };
      console.log(data,"点击查询按钮的时候传递的参数")
      pricingTask.findAllBlock(data).then((res)=>{
        if (res.code == 200) {
          this.blockModelData = res.datas.rows;
        }
        console.log(this.blockModelData, "blockModelData");
      });
    },
        handleSizeChange(val) {
      this.recordForm.size = val;
      this.toSubRecord();
      console.log(val, "每页数");
    },
    handleCurrentChange(val) {
      this.recordForm.page = val;
      this.toSubRecord();
      console.log(val, "当前页");
    },
        blockhandleSizeChange(val) {
      this.blockForm.size = val;
      this.toBlock();
      console.log(val, "每页数");
    },
    blockhandleCurrentChange(val) {
      this.blockForm.page = val;
      this.toBlock();
      console.log(val, "当前页");
    },
    goBack(){
      this.subRecord = false;
      this.block = false;
      this.$emit("backIndex", "");
    },
    getstatus(data) {
      getDict(data).then((res) => {
        if (res.code == 200) {
          this.statusOption = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    toBlock() {
      // this.getstatus("ftp_pricing_task_status");
      // // let selection = this.$refs.multipleTable.selection;
      // // if (selection.length != 1) {
      // //   return this.$message.warning("请选择一条数据");
      // // }
      // let data = { pricingCode: this.recordForm.pricingCode };
      // pricingTask.toBlock(data).then((res) => {
      //   if (res.code == 200) {
      //     this.positionOptions = res.data.positions;
      //     this.blockForm.taskCode = res.data.pricingTask.taskCode;
      //     this.blockForm.dataDate = res.data.pricingTask.dataDate;
      //   }
      //   console.log(this.recordForm, "recordForm");
      // });
      // this.blockForm.taskName = this.recordForm.taskName;
      // this.blockForm.pricingCode = this.recordForm.pricingCode;
      // // this.blockForm.dataDate = this.recordForm.dataDate;
      
      // console.log(this.blockForm, "blockForm");
      // let pagedata = { pricingCode: this.recordForm.pricingCode,
      // page:this.blockForm.page,
      // size:this.blockForm.size,
      //  };
      // pricingTask.findAllBlock(data).then((res) => {
      //   console.log(res, "跳转引擎任务的时候chaxundaodeshujv==============");
      //   if (res.code == 200) {
      //     this.blockModelData = res.datas.rows;
      //   }
      //   console.log(this.blockModelData, "blockModelData");
      // });
      // this.block = true;
      // this.subRecord = false;
      console.log(this.recordForm,"引擎传值")
      this.$emit("toEngineTask", this.recordForm);
    },
    toRecord() {
      this.subRecord = false;
      this.block = false;
      this.code = this.recordForm.taskCode;
console.log("code："+this.code);
  //  this.recordDi = true;
        this.$emit("toExcuteNotes", "");

    },
    searchFunc() {
      this.recordFrom = this.subRecordFrom;
    },
    toSubRecord() {
      // let selection = this.$refs.multipleTable.selection;
      // if (selection.length != 1) {
      //   return this.$message.warning("请选择一条数据");
      // }
      let data = { pricingCode: this.recordForm.pricingCode };
      pricingTask.toBlock(data).then((res) => {
        console.log(res, "跳转子任务的时候chaxundaodeshujv==============");
        if (res.code == 200) {
          this.recordForm.taskName = res.data.pricingTask.taskName;
          this.recordForm.taskCode = res.data.pricingTask.taskCode;
          this.recordForm.pricingCode = res.data.pricingRecord.pricingCode;
          this.recordForm.dataDate = res.data.pricingRecord.dataDate;
        }
        console.log(this.recordForm, "recordForm");
      });
      let pagedata = 
      { pricingCode: this.recordForm.pricingCode,
      page:this.recordForm.page,
      size:this.recordForm.size,
       };
      pricingTask.findAllSubRecord(pagedata).then((res) => {
        console.log(res, "跳转子任务的时候chaxundaodeshujv==============");
        if (res.code == 200) {
          this.subRecordModelData = res.datas.rows;
          this.total = res.datas.total;
        }
        console.log(this.subRecordModelData, "subRecordModelData");
      });
      this.subRecord = true;
      this.block = false;
    },
    formatRunStatus(row, column) {
      if (row.status == "INIT") {
        return "初始化";
      } else if (row.status == "PREPARING") {
        return "准备中";
      } else if (row.status == "RUNNING") {
        return "运行中";
      } else if (row.status == "FINISH") {
        return "已完成";
      } else if (row.status == "ERROR") {
        return "错误";
      } else if (row.status == "SENDBACK") {
        return "已退回";
      } else if (row.status == "RETRY") {
        return "再次尝试中";
      } else {
        return "";
      }
    },
    //点击行选中
    authorizeModelFor(row) {
      if (this.$refs.subRecordModelTable) {
        this.$refs.subRecordModelTable.clearSelection();
      }
      this.$refs.subRecordModelTable.toggleRowSelection(row, true);
    },
    rowClick(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
      }
      this.$refs.multipleTable.toggleRowSelection(row, true);
    },

  },
};
</script>
<style lang="scss" scoped>

.formTitle {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 10px;
}
</style>
